home *** CD-ROM | disk | FTP | other *** search
/ PC Format Collection 21 / PC Format CD-ROM Collection 21 (1995-12)(Future Publishing)(GB)[issue 51].iso / resource / ctype.h < prev    next >
C/C++ Source or Header  |  1990-11-26  |  4KB  |  102 lines

  1. /****************************************************************************
  2.  * CTYPE.H        Character classification and conversion
  3.  *
  4.  *              This header file is coded such that it gives better
  5.  *                performance than the CTYPE.H file that comes with most C
  6.  *                compilers, mainly by eliminating an addition operation for
  7.  *                each use of an iswhatever(c) function. (Most CTYPE systems
  8.  *                use [c+1] to handle EOF, we handle it better.)
  9.  *
  10.  *                This file also provides a 'roll your own' typing function,
  11.  *                'isctype()'.  This macro allows testing of any arbitrary
  12.  *                combo of types.  For example, to check whether a character
  13.  *                is either space or punctuation, code 'isctype(c, _CTp|_CTs)'.
  14.  *
  15.  *                To use this file with non-Poco compilers, it is necessary to
  16.  *                define the symbol GENERATE_CTYPE_TABLE (before the #include 
  17.  *                for this file) in at least one of the modules that uses this
  18.  *                file.
  19.  *
  20.  * 10/30/90 -     Ported to poco.
  21.  * 11/22/90 -     Tested extensively, fixed a couple typos causing wrong results.
  22.  *                Also, added a couple #ifdef sections so that this file will
  23.  *                  work with any compiler, not just poco.
  24.  ***************************************************************************/
  25.  
  26. #ifndef CTYPE_H
  27. #define CTYPE_H
  28. #define _CTYPE_H_INCLUDED            /* for Watcom */
  29.  
  30. #if defined(__POCO__) || defined(GENERATE_CTYPE_TABLE)
  31.  
  32. signed char ___pctype[257] = {
  33.     0x00, /* EOF */
  34.     0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
  35.     0x80, 0x90, 0x90, 0x90, 0x90, 0x90, 0x80, 0x80,
  36.     0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
  37.     0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
  38.     0x10, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  39.     0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  40.     0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
  41.     0x42, 0x42, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  42.     0x20, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x04,
  43.     0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
  44.     0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
  45.     0x04, 0x04, 0x04, 0x20, 0x20, 0x20, 0x20, 0x21,
  46.     0x20, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x08,
  47.     0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
  48.     0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
  49.     0x08, 0x08, 0x08, 0x20, 0x20, 0x20, 0x20, 0x80,
  50.     };
  51.  
  52. signed char *__pctype = &___pctype[1];
  53.  
  54. #else
  55.  
  56. extern signed char *__pctype;
  57.  
  58. #endif /* __POCO__ or GENERATE_CTYPE_TABLE */
  59.  
  60. #define _CTb    0x0001 /* underbar, used by iscsym() */
  61. #define _CTd    0x0002 /* numeric digit */
  62. #define _CTu    0x0004 /* upper case */
  63. #define _CTl    0x0008 /* lower case */
  64. #define _CTs    0x0010 /* whitespace */
  65. #define _CTp    0x0020 /* punctuation */
  66. #define _CTx    0x0040 /* hexadecimal */
  67. #define _CTc    0x0080 /* control character */
  68.  
  69. #undef  _toupper
  70. #undef  _tolower
  71. #undef  toascii
  72. #define _toupper(c)  ((c)&0xFFDF)
  73. #define _tolower(c)  ((c)|0x0020)
  74. #define toascii(c)   ((c)&0x7F)
  75.  
  76. #define isascii(c)   (!((c)&0x0080))
  77. #define isalnum(c)   (__pctype[(c)]&(_CTu|_CTl|_CTd))
  78. #define isalpha(c)   (__pctype[(c)]&(_CTu|_CTl))
  79. #define iscntrl(c)     (__pctype[(c)]&_CTc)
  80. #define isdigit(c)     (__pctype[(c)]&_CTd)
  81. #define isgraph(c)   (__pctype[(c)]&(_CTd|_CTu|_CTl|_CTp))
  82. #define islower(c)     (__pctype[(c)]&_CTl)
  83. #define isprint(c)   (__pctype[(c)]>0)
  84. #define ispunct(c)     (__pctype[(c)]&_CTp)
  85. #define isspace(c)     (__pctype[(c)]&_CTs)
  86. #define isupper(c)     (__pctype[(c)]&_CTu)
  87. #define isxdigit(c)  (__pctype[(c)]&_CTx)
  88.  
  89. #define iscsym(c)     (__pctype[(c)]&(_CTu|_CTl|_CTb|_CTd))
  90. #define iscsymf(c)   (__pctype[(c)]&(_CTu|_CTl|_CTb))
  91. #define isctype(c,t) (__pctype[(c)]&(t)) /* roll your own combo */
  92.  
  93. #if defined(__POCO__) || defined(GENERATE_CTYPE_TABLE)
  94.   int toupper(int c) {if (islower(c)) return c&0xFFDF; else return c;}
  95.   int tolower(int c) {if (isupper(c)) return c|0x0020; else return c;}
  96. #else
  97.   extern int toupper(int);
  98.   extern int tolower(int);    
  99. #endif
  100.  
  101. #endif
  102.